import turtle
import random


def goto(p):
    turtle.up()
    turtle.goto(p)
    turtle.down()

def make_dot():
    x=random.randint(-300,300)
    y=random.randint(-300,300)
    return [x, y]
make_dot()
pos=[[30,0],[60,0],[90,0]]

num = 0
def draw():
    global num
    turtle.clear()
    if num==10:
        food.append(make_dot())
        num = 0
    num+=1
    for i in food:
        goto(i)
        turtle.dot(30, 'gold')
    for i in range(len(pos)):
        goto(pos[i])
        turtle.dot(30,'red')
    move()
    turtle.ontimer(draw, 200)
def move():
    if turtle.heading() == 90:
        pos.pop(0)
        pos.append([pos[-1][0], pos[-1][1]+30])
    if turtle.heading() == 180:
        pos.pop(0)
        pos.append([pos[-1][0] - 30, pos[-1][1]])
    if turtle.heading() == 0:
        pos.pop(0)
        pos.append([pos[-1][0] +30, pos[-1][1]])
    if turtle.heading() == 270:
        pos.pop(0)
        pos.append([pos[-1][0], pos[-1][1]-30])



def up():
    turtle.seth(90)

def left():
    turtle.seth(180)
def right():
    turtle.seth(0)
def down():
    turtle.seth(270)
food = [make_dot()]
draw()
turtle.onkeypress(up,'Up')
turtle.onkeypress(left,'Left')
turtle.onkeypress(right,'Right')
turtle.onkeypress(down,'Down')
turtle.listen()
turtle.tracer(False)












turtle.done()